package com.spr.validation;

import org.springframework.validation.Errors;

import org.springframework.stereotype.Component;
import org.springframework.validation.ValidationUtils;
import org.springframework.validation.Validator;

import com.spr.model.Student;


@Component
public class SignUpValidator implements Validator{

	  private final static String STUDENT_ID = "studentID";
	
	
	@Override
	public boolean supports(Class<?> arg0) {
		   return Student.class.isAssignableFrom(arg0);
	}

	@Override
	public void validate(Object target, Errors errors) {
		   Student student = (Student) target;
           Integer studentId = null;
           studentId = student.getStudentID();
           
           ValidationUtils.rejectIfEmpty(errors, "firstName", "student.firstName.empty");
           ValidationUtils.rejectIfEmpty(errors, "lastName", "student.lastName.empty");
           
           //ValidationUtils.rejectIfEmpty(errors, STUDENT_ID, "student.Id.empty");
           
           //if (studentId != null && studentId < 1)
             //      errors.rejectValue(STUDENT_ID, "student.Id.lessThanOne");

	}

}
